;;;Constructs ARCALIGNEDTEXT from standard text.
;;;Asks user to place a new arc which the text will be aligned to and erases the old text.
;;;
;;;	Author: Henry C. Francis
;;;		425 N. Ashe St.
;;;		Southern Pines, NC 28387
;;;
;;;	http://www.paracadd.com
;;;	All rights reserved.
;;;
;;;	Copyright:
;;;	   Edited:
;;;
;;;****************************************************************************
(DEFUN c:txt2arc ()
  (VL-LOAD-COM)
  (SETQ txtsel (entsel)
        selcnt 1
        arc-text NIL
  )
  (WHILE (OR (AND (NOT txtsel) (< selcnt 3)) (IF txtsel (/= (TYPE (CAR txtsel)) 'ENAME)))
    (SETQ selcnt (1+ selcnt)
          txtsel (entsel)
    )
  )
  (IF (AND txtsel (EQ (TYPE (CAR txtsel)) 'ENAME))
    (PROGN
      (SETQ curr_layer (GETVAR "CLAYER"))
      (IF upoint NIL (LOAD "upoint" "\nFile UPOINT.LSP not loaded! "))
      (IF gvpno NIL (LOAD "gvpno" "\nFile GVPNO.LSP not loaded! "))
      (gvpno)
      (IF uint NIL (LOAD "uint" "\nFile UINT.LSP not loaded! "))
      (IF viewno NIL (SETQ viewno (uint 1 "" "View number?" 2)))
      (SETQ mjrg "C")
      (IF make_layer_ent NIL (LOAD "make_layer_ent" "\nFile MAKE_LAYER_ENT.LSP not loaded! "))
      (SETQ nplt-layer (STRCAT mjrg "-VI" (IF (< viewno 10) "0" "") (ITOA viewno) "7NOTE-NPLT"))
      (make_layer_ent (LIST (CONS 8 nplt-layer)))
      (COMMAND ".ARC"
               (SETQ arcpt1 (upoint 1 "" "Specify start point of arc:" nil nil))
               (SETQ arcpt2 (upoint 1 "" "Specify second point of arc:" nil nil))
               (SETQ arcpt3 (upoint 1 "" "Specify end point of arc:" nil nil))
      )
      (SETQ arc-ent (ENTGET (ENTLAST))
            text-edata (ENTGET (CAR txtsel))
            text-str (CDR (ASSOC 1 text-edata))
            text-layer (CDR (ASSOC 8 text-edata))
      )
      (SETVAR "CLAYER" text-layer)
      (dos_clipboard text-str)
      (COMMAND ".ARCTEXT" pause)
      (SETQ arc-text (ENTGET (ENTLAST)))
      (IF (AND (EQ (CDR (ASSOC 0 arc-text)) "ARCALIGNEDTEXT") (WCMATCH (CDR (ASSOC 1 arc-text)) text-str))
        (PROGN
          (SETQ arc-text
                 (SUBST (CONS 8 text-layer)
                        (ASSOC 8 arc-text)
                        arc-text
                 )
          )
          (ENTMOD arc-text)
        )
      )
      (IF ukword NIL (LOAD "ukword" "\nFile UKWORD.LSP not loaded! "))
      (SETQ maskarctxt (ukword 1 "Yes No" "Mask arctext? [Yes/No]" (IF maskarctxt maskarctxt "No")))
      (mask-arc-text)
      (COMMAND ".draworder" (CDR (ASSOC -1 arc-text)) "" "f")
      (ENTDEL (CAR txtsel))
      (SETVAR "CLAYER" curr_layer)
    )
    (PROGN
      (PRINC "\nNo TEXT entity was selected! ")
    )
  )
  (PRINC)
)
;;;****************************************************************************
(DEFUN C:TEXT2ARC () (C:TXT2ARC))
;;;****************************************************************************
;;;Constructs Hiding image under ARCALIGNEDTEXT.
(DEFUN C:HIDEARCTEXT ()
  (mask-arc-text)
)
(DEFUN C:HIDEARCTXT ()
  (mask-arc-text)
)
(DEFUN C:MASKARCTEXT ()
  (mask-arc-text)
)
(DEFUN C:MASKARCTXT ()
  (mask-arc-text)
)
;;;****************************************************************************
(DEFUN mask-arc-text ()
  (IF arc-text
    (SETQ arctxt-ename (CDR (ASSOC -1 arc-text)))
    (PROGN
      (SETQ arctxt-ss (SSGET '((0 . "ARCALIGNEDTEXT"))))
      (IF arctxt-ss
        (SETQ arctxt-ename (SSNAME arctxt-ss 0)
              arc-text (ENTGET arctxt-ename)
        )
      )
    )
  )
  (IF arc-text
    (PROGN
          (SETQ arctxt-edata (ENTGET arctxt-ename))
          (SETQ arctxt-obj (VLAX-ENAME->VLA-OBJECT arctxt-ename))
;;;          (SETQ arctxt-center-var (VLAX-GET-PROPERTY arctxt-obj 'Center))
;;;          (SETQ arctxt-center (VLAX-SAFEARRAY->LIST (VLAX-VARIANT-VALUE arctxt-cntr-var)))
          (SETQ arctxt-center (CDR (ASSOC 10 arctxt-edata)));object property 'Center is always bogus
          (SETQ arctxt-radius (CDR (ASSOC 40 arctxt-edata)));object property 'Radius is always bogus Edata gives true Radius of Arc
          (SETQ arctxt-height (ATOF (VLAX-GET-PROPERTY arctxt-obj 'Height)))
          (SETQ arctxt-offset (ATOF (VLAX-GET-PROPERTY arctxt-obj 'ArcOffset)))
          (SETQ arctxt-leftoffset (ATOF (VLAX-GET-PROPERTY arctxt-obj 'LeftOffset)))
          (SETQ arctxt-rightoffset (ATOF (VLAX-GET-PROPERTY arctxt-obj 'RightOffset)))
          (SETQ arctxt-startangle (VLAX-GET-PROPERTY arctxt-obj 'StartAngle));Arc start angle, LeftOffset is to the start of text from the start of the Arc
          (SETQ arctxt-endangle (VLAX-GET-PROPERTY arctxt-obj 'EndAngle));Arc end angle, RightOffset is to the end of text from the end of the Arc
          (SETQ arctxt-offside (CDR (ASSOC 72 arctxt-edata)));1 = Above, 2 = Below
          (SETQ this-hide-ss (SSADD))
          (ENTMAKE (LIST
                     (CONS 0 "ARC")
                     (CONS 100 "AcDbEntity")
                     (CONS 8 nplt-layer)
                     (CONS 10 arctxt-center)
                     (CONS 40 ((IF (EQ arctxt-offside 2) - +) arctxt-radius arctxt-offset (* 1.25 arctxt-height)))
                     (CONS 100 "AcDbArc")
                     (ASSOC 50 arctxt-edata)
                     (ASSOC 51 arctxt-edata)
                   )
          )
          (SSADD (ENTLAST) this-hide-ss)
          (SETQ arc1ent (ENTGET (ENTLAST)))
          (ENTMAKE (LIST
                     (CONS 0 "ARC")
                     (CONS 100 "AcDbEntity")
                     (CONS 8 nplt-layer)
                     (CONS 10 arctxt-center)
                     (CONS 40 ((IF (EQ arctxt-offside 2) + -) arctxt-radius (- arctxt-offset) (* 0.25 arctxt-height)))
                     (CONS 100 "AcDbArc")
                     (ASSOC 50 arctxt-edata)
                     (ASSOC 51 arctxt-edata)
                   )
          )
          (SSADD (ENTLAST) this-hide-ss)
          (SETQ arc2ent (ENTGET (ENTLAST)))
          (SETQ arc1obj (VLAX-ENAME->VLA-OBJECT (CDR (ASSOC -1 arc1ent))))
          (SETQ arc2obj (VLAX-ENAME->VLA-OBJECT (CDR (ASSOC -1 arc2ent))))
          (SETQ line1start (VLAX-GET-PROPERTY arc1obj 'StartPoint))
          (SETQ line1pt1 (VLAX-SAFEARRAY->LIST (VLAX-VARIANT-VALUE line1start)))
          (SETQ line1end (VLAX-GET-PROPERTY arc2obj 'StartPoint))
          (SETQ line1pt2 (VLAX-SAFEARRAY->LIST (VLAX-VARIANT-VALUE line1end)))
          (SETQ line2start (VLAX-GET-PROPERTY arc1obj 'EndPoint))
          (SETQ line2pt1 (VLAX-SAFEARRAY->LIST (VLAX-VARIANT-VALUE line2start)))
          (SETQ line2end (VLAX-GET-PROPERTY arc2obj 'EndPoint))
          (SETQ line2pt2 (VLAX-SAFEARRAY->LIST (VLAX-VARIANT-VALUE line2end)))
          (ENTMAKE (LIST
                     (CONS 0 "LINE")
                     (CONS 100 "AcDbEntity")
                     (CONS 8 nplt-layer)
                     (CONS 10 line1pt1)
                     (CONS 11 line1pt2)
                     (CONS 100 "AcDbLine")
                   )
          )
          (SSADD (ENTLAST) this-hide-ss)
          (ENTMAKE (LIST
                     (CONS 0 "LINE")
                     (CONS 100 "AcDbEntity")
                     (CONS 8 nplt-layer)
                     (CONS 10 line2pt1)
                     (CONS 11 line2pt2)
                     (CONS 100 "AcDbLine")
                   )
          )
          (SSADD (ENTLAST) this-hide-ss)
          (COMMAND ".pedit" "m" this-hide-ss "" "y" "j" "" "")
          (SETQ hide-pl-ss NIL)
          (SETQ bendpliness (SSADD (ENTLAST)))
          (IF C:HIDEBDRY NIL (LOAD "img" "\nFile IMG.LSP not loaded! "))
          (IF gvpno NIL (LOAD "gvpno" "\nFile GVPNO.LSP not loaded! "))
          (gvpno)
          (IF uint NIL (LOAD "uint" "\nFile UINT.LSP not loaded! "))
          (IF viewno NIL (SETQ viewno (uint 1 "" "View number?" 2)))
          (SETQ hide-layer (STRCAT mjrg "-VI" (IF (< viewno 10) "0" "") (ITOA viewno) "7MASK"))
          (make_layer_ent (LIST (CONS 8 hide-layer)))
          (C:HIDEBDRY)
          (SETQ arc-text NIL)
      )
    )
)
;;;****************************************************************************
;;;One method for making ARCALIGNEDTEXT
;;;From: https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/entmaking-arcalignedtext/m-p/862955#M88613
;;;User: rogerio_brazil
;;;(defun c:eat (/ string ArcOffset data name ang dxf40 dxf51 OffsetArc ins);Entmake Arc Text
;;;(setq string "")
;;;(while (= string "")(setq string (getstring t "\n Arctext string: ")))
;;;(setq ArcOffset (getdist "\n Text Offset from Arc <0>: "))
;;;(if (= ArcOffset nil)(setq ArcOffset 0))
;;;(setq data (entget (car (entsel "\n Pick Arc: "))))
;;;(setq name (cdr (assoc 330 data)))
;;;(setq ang (cdr (assoc 50 data)))
;;;(setq dxf40 (cdr (assoc 40 data)))
;;;(setq dxf51 (cdr (assoc 51 data)))
;;;(setq OffsetArc (+ dxf40 ArcOffset))
;;;(setq ins (cdr (assoc 10 data)))
;;;(entmake (list '(0 . "ARCALIGNEDTEXT")
;;;'(100 . "AcDbEntity")
;;;'(67 . 0)
;;;'(410 . "Model")
;;;'(8 . "0")
;;;'(100 . "AcDbArcAlignedText")
;;;(cons 1 string)
;;;'(2 . "txt")
;;;'(3 . "")
;;;'(7 . "Standard")
;;;(cons 10 ins)
;;;(cons 40 OffsetArc)
;;;'(41 . 1.0)
;;;'(42 . 3.0)
;;;'(43 . 0.095)
;;;'(44 . 0.0)
;;;'(45 . 0.0)
;;;'(46 . 0.0)
;;;(cons 50 ang)
;;;(cons 51 dxf51)
;;;'(70 . 0)
;;;'(71 . 1)
;;;'(72 . 1)
;;;'(73 . 1)
;;;'(74 . 0)
;;;'(75 . 0)
;;;'(76 . 0)
;;;'(77 . 1)
;;;'(78 . 0)
;;;'(79 . 1)
;;;'(90 . 256)
;;;(cons 210 '(0.0 0.0 1.0))
;;;'(280 . 1)
;;;(cons 330 name)
;;;)
;;;)
;;;(princ))
;;;****************************************************************************
(PRINC)